/**
 * 计算单项总计
 */
var calTotal = function(type){
	//订单销售单价
	var price = Number($('#price').val());
	
	
//	if(price < costPrice){
//		alertMsg.error('销售单价['+price+']小于成本单价['+costPrice+']，确定赔本销售吗!', {okCall: function(){$('#price').val('')}});
//		return ;
//	}
//	if(price == costPrice){
//		alertMsg.error('销售单价['+price+']等于成本单价['+costPrice+']，确定白干吗!', {okCall: function(){$('#price').val('')}});
//		return ;
//	}
	//判断是否大于库存量
	if(type==1){
		//订单项成本单价
		var costPrice = Number($('#costPrice').val()); 
		//从库房提货的订单项计算
		var storeNum = Number($('#storeNum').val());
		if(storeNum != 0){
			//var num = Number($('#num').val());
			var weight = Number($('#weight').val());
			if(weight > storeNum){
				alertMsg.error('出库重量['+weight+']大于库存重量['+storeNum+']，请重新填写!', {okCall: function(){}});
				$('#weight').val(storeNum);
				return ;
			}
		}
		//重量
		//var num = Number($('#num').val());
		var num ;
		var unit = $('#un').text();
		//如果以令为单位，按数据计算，否则以吨为单位，按重量
		if(unit == '令'){
			num = Number($('#num').val()).toFixed(3);
		}else{
			num = Number($('#weight').val()).toFixed(5);
		}
		
		//数量(重量)乘以单价=单项合计金额
		var result = num * price;
		var costResult = num * costPrice;
		//订单项销售总金额
		$('#amount').val(result.toFixed(2));
		//订单项成本总金额
		$('#costAmount_store').val(Number(costResult.toFixed(2)));
		$('#weight').val(num);
	}else{
		
		if(price > 0){
			//计算利润
			var lirun = price - Number($('#lirun').val().toFixed(2));
			$('#costPrice').val(lirun);
		}
		
		//订单项成本单价
		var costPrice = Number($('#costPrice').val()); 
		
		//从供货商提货的订单项计算	重量乘以单价 
		//var num = Number($('#num').val());
		var num ;
		var unit = $('#un').text();
		//如果以令为单位，按数量计算，否则以吨为单位，按重量
		if(unit == '令'){
			num = Number($('#num').val()).toFixed(3);
			$('#weight').val(0);
		}else{
			num = Number($('#weight').val()).toFixed(5);
			$('#weight').val(num);
		}
		
		//var price = Number($('#price').val());
		//var costPrice = Number($('#costPrice').val());
		//数量(重量)乘以单价=单项合计金额
		var result = num * price;
		
		var costResult = num * costPrice;
		//订单项销售总金额
		$('#amount').val(result.toFixed(2));
		//订单项成本总金额
		$('#costAmount_addItem').val(Number(costResult.toFixed(2)));
		
		
	}
	
}
/**
 * 计算成本
 * @returns
 */
var calCostTotal = function(){
	var num;
	var unit = $('#un').text();
	//如果以令为单位，按数量计算，否则以吨为单位，按重量
	if(unit == '令'){
		num = Number($('#num').val()).toFixed(3);
		
	}else{
		num = Number($('#weight').val()).toFixed(5);
	}
	//订单项成本单价
	var costPrice = Number($('#costPrice').val()); 
	var costResult = num * costPrice;
	//订单项成本总金额
	$('#costAmount_addItem').val(Number(costResult.toFixed(2)));
	$('#costAmountTx').text(costResult.toFixed(2));
	
}

/**
 * 计算订单总金额
 * @returns
 */
var calOrderTotal = function(){
	
	
}